package net.learn.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import net.learn.framework.common.page.PageResult;
import net.learn.framework.common.utils.Result;
import net.learn.system.query.SysCheckBoxDetailQuery;
import net.learn.system.query.SysCheckBoxQuery;
import net.learn.system.service.SysCheckBoxDetailService;
import net.learn.system.vo.SysCheckBoxDetailVO;
import net.learn.system.vo.SysCheckBoxVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 多选管理
 */
@RestController
@RequestMapping("sys/checkboxdetail")
@Tag(name="多选管理")
@AllArgsConstructor
public class SysCheckBoxDetailController {
    @Autowired
    SysCheckBoxDetailService checkBoxDetailService;

    @GetMapping("getCheckBoxDetail")
    @Operation(summary = "分页获取多选题详情列表")
    public Result<PageResult<SysCheckBoxDetailVO>> getCheckBoxDetail(@Valid SysCheckBoxDetailQuery query){
        PageResult<SysCheckBoxDetailVO> page = checkBoxDetailService.qryCheckBoxDetailListPage(query);
        return Result.ok(page);
    }
    @PostMapping("getCheckBoxDetailList")
    @Operation(summary = "获取多选题详情列表")
    public Result<List<SysCheckBoxDetailVO>> getCheckBoxDetailList(@RequestBody @Valid SysCheckBoxDetailQuery query){
        List<SysCheckBoxDetailVO> list = checkBoxDetailService.getCheckBoxDetailArray();

        return Result.ok(list);
    }
    @PostMapping("getPaperCheckBoxList")
    @Operation(summary = "获取试卷题库列表")
    public Result<List<SysCheckBoxDetailVO>> getPaperCheckBoxList(@RequestBody @Valid SysCheckBoxDetailQuery query){
        List<SysCheckBoxDetailVO> list = checkBoxDetailService.qryPaperCheckBoxList(query);

        return Result.ok(list);
    }
    @PostMapping("getPaperCheckBoxCondition")
    @Operation(summary = "获取正在考试试卷题库列表")
    public Result<List<SysCheckBoxDetailVO>> getPaperCheckBoxCondition(@RequestBody @Valid SysCheckBoxDetailQuery query){
        List<SysCheckBoxDetailVO> list = checkBoxDetailService.qryPaperCheckBoxCondition(query);

        return Result.ok(list);
    }
    @PostMapping("/updateCheckBoxDetail")
    @Operation(summary = "修改多选题详情")
    public Result<String> updateCheckBox(@RequestBody @Valid SysCheckBoxDetailVO vo){
        checkBoxDetailService.updateCheckBoxDetail(vo);

        return Result.ok();
    }
    @PostMapping("save")
    @Operation(summary = "新增多选题详情")
    public Result<String> save(@RequestBody List<SysCheckBoxDetailVO> checkBoxDetailList){
        for (SysCheckBoxDetailVO checkBoxDetailVO:checkBoxDetailList){

            checkBoxDetailService.addCheckBoxDetail(checkBoxDetailVO);
        }

        return Result.ok();
    }

    @DeleteMapping
    @Operation(summary = "删除")
    public Result<String> delete(@RequestBody List<Long> idList){

        checkBoxDetailService.delete(idList);
        return Result.ok();
    }
}

